findRichText (help needed)

Hello,

 

Is there a way of selecting some text and replacing it with it's plainText ? Meaning I would like to select the word BOLD along with it  markup so basically removing all richText formatting? I don't want to remove all of the richText within "Object Text". Thank you

 

Object o = current
string currentObject = richTextWithOle o."Object Text"

//This dxl prints the current selected text from a module
callStdItem_(clipCopyFlatItem)
string strRichString = stringOf(richClip)
//print "Selected Text = " (strRichString) "\n"

string sub = plainText(strRichString) /* richTextFragment */
int offset
int len
if (findRichText(currentObject, sub, offset, len, false)) {
        //print "Offset = " offset "\n"
        //print "Length = " len "\n"
        o."Object Text" = richText replaceRichText(currentObject, offset, len, sub)
} else {
        ack "Failed to match"
}

 


EHcnck - Sun Jan 22 00:58:58 EST 2017

Re: findRichText (help needed)
Mathias Mamsch - Sun Jan 22 07:25:04 EST 2017

Well did you try to first replace with nothing, then insert the new unformatted string manually? 

string search = "bold"; 
string replace = "new"
string s = "{\\b This is Bo{\\i ld and italic}}"

int len = 0, off = 0; 

if (findRichText(s, search, off, len, false)) {
   // remove the old string
   string result = replaceRichText(s, off, len, "")

   // insert the new string
   string first = (off > 0) ? result[0:off-1] : ""; 
   string last  = (off+1 <= length(result)) ? result[off:] : ""; 
   result = first replace last
   print "Result: " result "\n";
} else {
  print search " not found!"; 
}

This way the string will get the formatting of the previous word. If you do not want that you might want to try inserting something like 

...
result = first "{\\plain " replace "}" last
...

Hope this helps, regards, Mathias

Re: findRichText (help needed)
EHcnck - Sun Jan 22 09:56:20 EST 2017

Mathias Mamsch - Sun Jan 22 07:25:04 EST 2017

Well did you try to first replace with nothing, then insert the new unformatted string manually? 

string search = "bold"; 
string replace = "new"
string s = "{\\b This is Bo{\\i ld and italic}}"

int len = 0, off = 0; 

if (findRichText(s, search, off, len, false)) {
   // remove the old string
   string result = replaceRichText(s, off, len, "")

   // insert the new string
   string first = (off > 0) ? result[0:off-1] : ""; 
   string last  = (off+1 <= length(result)) ? result[off:] : ""; 
   result = first replace last
   print "Result: " result "\n";
} else {
  print search " not found!"; 
}

This way the string will get the formatting of the previous word. If you do not want that you might want to try inserting something like 

...
result = first "{\\plain " replace "}" last
...

Hope this helps, regards, Mathias

 

Is there a why of getting the true representation of the selected text. meaning when I select Milk I want what is in the actual Object Text rtf not what the  richTextFragment function is giving which is in this case doesn't Match 100%. Thank you.

 

 

Object Text

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}}
{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sa8\f0\fs20 <span style="background-color: #FFFF00">Yellow text.</span> Testing script \ul\b Milk\ulnone\b0  <Hello>\par
}

richTextFragment: \b \ul Milk\b0 \ul0 

 

Re: findRichText (help needed)
Mathias Mamsch - Sun Jan 22 16:15:57 EST 2017

EHcnck - Sun Jan 22 09:56:20 EST 2017

 

Is there a why of getting the true representation of the selected text. meaning when I select Milk I want what is in the actual Object Text rtf not what the  richTextFragment function is giving which is in this case doesn't Match 100%. Thank you.

 

 

Object Text

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}}
{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sa8\f0\fs20 <span style="background-color: #FFFF00">Yellow text.</span> Testing script \ul\b Milk\ulnone\b0  <Hello>\par
}

richTextFragment: \b \ul Milk\b0 \ul0 

 

Is this a new question or somehow related to your question above? I am not sure, I understand what you are looking for, when you say "true represenation of selected text" ... Are you selecting some Object text and trying to get a full richtext representation (with header) only containing the selection? Regards, Mathias